package com.wwwarehouse.taskcenter.fragment.job_point.step2.child;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import com.wwwarehouse.common.activity.base.BaseFragment;
import com.wwwarehouse.taskcenter.R;
import com.wwwarehouse.taskcenter.constant.job_point.TaskCenterCommon;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Jackie on 2017/10/27
 * 子作业点使用权维度  选择添加方式
 */


public class ChooseAddWayChildUseRightFragment extends BaseFragment implements View.OnClickListener {
    private View mRootView;

    private RelativeLayout mWayAnyLayout;
    private RelativeLayout mWayBusinessLayout;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mRootView = inflater.inflate(R.layout.fragment_choose_add_way_child_use_right, container, false);
        return mRootView;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        initView();
        initData();
        initEvent();
    }

    private void initView() {
        mWayAnyLayout = findView(mRootView, R.id.rl_way_any);
        mWayBusinessLayout = findView(mRootView, R.id.rl_way_business);
    }

    private void initData() {

    }

    private void initEvent() {
        mWayAnyLayout.setOnClickListener(this);
        mWayBusinessLayout.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();

        if (id == R.id.rl_way_any) {
            popFragment();

            buildAnyMap();

            Intent intent = new Intent("ChooseAddWayChildUseRightByAny");
            mActivity.sendBroadcast(intent);
        } else if (id == R.id.rl_way_business) {
            //从业务单位选择
            pushFragment(new ChooseAddWayChildUseRightByBusinessFragment());
        }
    }

    @Override
    public void setTitle() {
        if (peekFragment() instanceof ChooseAddWayChildUseRightFragment) {
            mActivity.setTitle(R.string.choose_add_type);
        }
    }

    @Override
    public void requestDatas() {

    }

    private void buildAnyMap() {
        Map map = new HashMap();
        List<Map<String, String>> list = new ArrayList<>();
        Map<String, String> listMap = new HashMap<>();

        listMap.put("key", "-10002");
        listMap.put("value", "任意");

        list.add(listMap);

        map.put("list", list);
        map.put("type", "CONSTANT");

        if (TaskCenterCommon.getInstance().isStart()) {
            TaskCenterCommon.getInstance().setStartMap(map);
        } else {
            TaskCenterCommon.getInstance().setEndMap(map);
        }
    }
}
